package client.comm.baoding.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.comm.commlib.network.data.JsonResult
import client.comm.commlib.network.data.Ret
import client.comm.baoding.ui.viewmodel.MiddleVm
import kotlinx.coroutines.flow.*

class CreateRechargeViewModel(app: Application) : MiddleVm(app) {
    val isShowing = MutableLiveData<Boolean>(false)
    val num = MutableLiveData<String>()
    val okCall = MutableLiveData<JsonResult<Ret>>()
    val txType = MutableLiveData<Int>(-1)

    fun checkYj() {
        txType.value = 1
    }

    fun ok() {
        this@CreateRechargeViewModel.isShowing.value = true
        hold({
            server.recharge_orders(num.value!!, "${txType.value}")
        }, {
            isShowing.value = true
        }, success = {
            okCall.value = it
        }, complete = {
            isShowing.value = false
        })
    }

}